Skip to content

Chore: switch tests from freezegun to time-machine#3516

Merged
treysp merged 7 commits intomainfrom
trey/time-machine
Dec 16, 2024
Merged

Chore: switch tests from freezegun to time-machine#3516
treysp merged 7 commits intomainfrom
trey/time-machine

Conversation

@treysp
Copy link
Copy Markdown
Contributor

@treysp treysp commented Dec 13, 2024

Libraries used for freezing time in the sqlmesh unit tests.

Change motivated by freezegun's inability to handle timezones.

Notes:

  • Default behavior
    • freezegun default is for time to be totally frozen inside the context, such that repeatedly capturing now() would give the same value every time
    • time_machine default is for time to continue inside the context
    • in the tests where it's relevant, we specify tick=False to retain freezegun's default behavior
  • Time zones
    • time_machine infers tz as UTC for objects that are not tz-aware
    • If a tz-aware object is present without an explicit tz, the machine's local tz will be used
    • We manually specify UTC everywhere to avoid mixing tz-aware and non-tz-aware objects

@treysp treysp changed the title Chore: switch tests from freezetime to time_machine library Chore: switch from freezetime to time_machine library Dec 13, 2024
@treysp treysp marked this pull request as ready for review December 14, 2024 00:18
@treysp treysp requested a review from eakmanrq December 14, 2024 00:19
@treysp treysp changed the title Chore: switch from freezetime to time_machine library Chore: switch from freezetime to time-machine library Dec 14, 2024
Comment thread tests/cli/test_cli.py
Comment thread tests/core/test_integration.py
@treysp treysp changed the title Chore: switch from freezetime to time-machine library Chore: switch tests from freezetime to time-machine library Dec 14, 2024
@treysp treysp force-pushed the trey/time-machine branch 2 times, most recently from e3512e6 to 9129b2d Compare December 14, 2024 18:32
@treysp treysp changed the title Chore: switch tests from freezetime to time-machine library Chore: switch tests from freezetime to time-machine Dec 14, 2024
@treysp treysp changed the title Chore: switch tests from freezetime to time-machine Chore: switch tests from freezegun to time-machine Dec 14, 2024
Comment thread setup.py
@treysp treysp merged commit cc0330e into main Dec 16, 2024
@treysp treysp deleted the trey/time-machine branch December 16, 2024 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants